/**************************************************************************
 *
 * Copyright (C) 2007 University of California, Los Angeles.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 *************************************************************************/

/**
 * 
 */
package edu.ucla.cs.typecast.event;

import java.util.Collection;

import edu.ucla.cs.typecast.util.TypeUtil;

/**
 *
 * @date Jul 26, 2007
 */
public class EventRegistrationEntry {
	private Class[] types; 
	private EventListener listener; 
	private Object handback; 
	public EventRegistrationEntry(Class[] types, EventListener listener, Object handback) { 
		this.types = types; 
		this.listener = listener; 
		this.handback = handback; 
	}	
	public Class[] getTypes() { 
		return types; 
	}
	public EventListener getEventListener() { 
		return listener; 
	}	
	public Object getHandback() { 
		return handback; 
	}

	/**
	 * Check whether the types of a specific event matches this registration entry. 
	 * A match is true if the reigstered type is super type of event types. 
	 * @param eventTypes
	 * @return
	 */
	public boolean match(Collection<Class> eventTypes) { 
		for(Class type : types) { 
			if(!eventTypes.contains(type)) { 
				return false; 
			}
		}
		return true; 
	}
	
	public int hashCode() { 
		return listener.hashCode(); 
	}
	
	public boolean equals(Object another) { 
		if (another instanceof EventRegistrationEntry) { 
			EventRegistrationEntry entry = (EventRegistrationEntry)another; 
			return listener.equals(entry.getEventListener());
		}
		return false; 
	}
	
}
